import { crud } from '@xtail/pouchdb'
import { PathConst } from '@xtail/electron'
import { SSHUtil } from '@xtail/ssh'

export const [, , saveHostConnConfs, findHostConnConfs, , removeHostConnConfsByIds] = crud({
  dbName: 'host-conn-conf.db',
  dbPath: PathConst.UserData()
})

export const testConn = async (hostConnConf: HostConnConfType) => {
  const res = await SSHUtil.testConnWithErrMiddleware(hostConnConf)
  return ResultUtil.genResult({
    status: res.success,
    message: res.message,
    data: res.detail
  })
}

export type TestConnType = typeof testConn
